package co.fitstart.coach.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import co.fitstart.coach.service.PrincipalService;
import co.fitstart.coach.web.resolver.Secure;
import co.fitstart.entity.principal.Principal;

/**
 * 
 * @author lidan
 *
 */
@Controller
@RequestMapping("/profile")
public class ProfileController {

    @Autowired
    private PrincipalService principalService;
    
    /**
     * profile index
     * 
     * @param id
     * @return
     */
    @RequestMapping(value = "", method = RequestMethod.GET)
    public ModelAndView index(@Secure(property = "id") Long id){
        
        ModelAndView modelAndView = new ModelAndView("profile/profile-index");
        
        Principal principal = principalService.load(Principal.class, id);
        
        modelAndView.addObject("principal", principal);
        
        return modelAndView;
    }

}
